package ai4games_tests.guides;

import game2dai.Domain;
import game2dai.World;
import game2dai.entities.MovingEntity;
import game2dai.entityshapes.ps.ArrowPic;
import game2dai.entityshapes.ps.CirclePic;
import game2dai.entityshapes.ps.Hints;
import game2dai.entityshapes.ps.PersonPic;
import game2dai.maths.Vector2D;
import game2dai.steering.SBF;
import game2dai.utils.StopWatch;
import processing.core.PApplet;

public class SimpleMovement_2 extends PApplet {
	// Global variable declaration area
	World world;
	StopWatch sw;
	MovingEntity mover0;
	
	
	public void setup(){
		size(480,320);
		world = new World(width, height);
		sw = new StopWatch();
		// Create the mover
		mover0 = new MovingEntity(new Vector2D(width/2,height/2), // position
				10, // collision radius
				new Vector2D(15,15), // velocity
				40, // maximum speed
				new Vector2D(1,1), // heading
				1, // mass
				0.5,  // turning rate
				200 // max force
		); 
		// What does this mover look like
		ArrowPic view = new ArrowPic(this);		
//		CirclePic view = new CirclePic(this);		
//		PersonPic view = new PersonPic(this);		
		view.showHints(Hints.HINT_COLLISION | Hints.HINT_HEADING | Hints.HINT_VELOCITY);
		mover0.renderer(view);
		// Constrain movement
		Domain d = new Domain(60,60,width-60,height-60);
		mover0.worldDomain(d, SBF.REBOUND);
//		mover0.worldDomain(d, SBF.WRAP);
//		mover0.worldDomain(d, SBF.PASS_THROUGH);
		// Finally we want to add this to our game domain
		world.add(mover0);
		sw.reset();
	}
	
	public void draw(){
		double elapsedTime = sw.getElapsedTime();
		world.update(elapsedTime);
		background(200,255,200);
		// Make the movers constraint area visible
		Domain d = mover0.worldDomain();
		fill(255,200,200);
		noStroke();
		rect((float)d.lowX, (float)d.lowY, (float)d.width, (float)d.height);
		world.draw(elapsedTime);

	}
}

